package com.hotelsystem.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hotelsystem.pojo.Logging;
import com.hotelsystem.pojo.vo.LoggingQueryVo;
import com.hotelsystem.service.LoggingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RequestMapping("/logging")
@Controller
public class LoggingController {

    @Resource(name = "loggingServiceImpl")
    private LoggingService loggingService;

    @RequestMapping("/toLogging")
    public String toLogging(LoggingQueryVo loggingQueryVo,Integer pageNum,Model model) {
        //2019-07-10 22:38:10.0
         try {
            //设置当前页和每页数量
            PageHelper.startPage(pageNum,5);
            //设置查询条件
            List<Logging> loggingLists = loggingService.getAllLoggingLists(loggingQueryVo);
            //获取PageInfo对象，该对象封装的分页的相关信息
            PageInfo<Logging> pageInfo = new PageInfo<>(loggingLists);
            //查询分页
             model.addAttribute("pageInfo",pageInfo);
            //数据回显
            model.addAttribute("loggingQueryVo",loggingQueryVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "room/logging/loggingInfo";
    }

    /**
     * 删除日志通过Id
     * @param loggingId
     * @return
     */
    @RequestMapping("/deleteLoggingInfo")
    @ResponseBody
    public Object deleteRoomInfoWithId(Integer loggingId){
        Map<String,Object> maps = new HashMap<>();
        try {

            loggingService.deleteLoggingInfo(loggingId);
            maps.put("success",true);
        } catch (Exception e) {
            maps.put("success",false);
            e.printStackTrace();
        }
        return maps;
    }

}
